package com.sultan.guante.userSystem.domain;



import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;


import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.sultan.guante.userSystem.dao.AddressDAO;
import com.sultan.guante.userSystem.dao.CredentialDAO;
import com.sultan.guante.userSystem.dao.BaseDAO;

import com.sultan.guante.userSystem.dao.RoleDAO;
import com.sultan.guante.userSystem.dao.UserDAO;
import com.sultan.guante.userSystem.dao.impl.AddressDAOImpl;
import com.sultan.guante.userSystem.dao.impl.BaseDAOImpl;
import com.sultan.guante.userSystem.dao.impl.CredentialDAOImpl;
import com.sultan.guante.userSystem.dao.impl.RoleDAOImpl;
import com.sultan.guante.userSystem.dao.impl.UserDAOImpl;

public class Main {

public static Long num;
	/**
	 * @param <T>
	 * @param <T>
	 * @param args
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static <T> void main(String[] args) {
		// TODO Auto-generated method stub

		
		ApplicationContext appContext = new ClassPathXmlApplicationContext("/Spring/spring-master.xml");

		
// para ASPECTJ ApplicationContext appContext = new ClassPathXmlApplicationContext("/Spring/SpringCustomer.xml");

		
		
		RoleDAO roleDaoBean = (RoleDAO) appContext.getBean("RoleDaoBean");		
		
	/* CREAR ROLE */
		
		
		RoleDAO roleDAO = new RoleDAOImpl();
        
   ///     RoleDAO roleDAO = new RoleDAOImpl();
        Role role = new Role();
        
        role.setName("administrador");
        roleDAO.save(role);

        
      
        //EStas 2  si me funcionan
       // baseDao2.save2(); 
      //  genericDao.save((T) role);
        
        
        roleDaoBean.save(role);
        
        
        
     //   baseDao.save(role);
     //   baseDao2.save(role);
        
     //   roleDaoBean.save(role);
        
     //   roleDaoImpl.save(role); 
      
        
        
        Role role2 = new Role();
        role2.setName("ingeniero");
        
        roleDAO.save(role2);
        
        List<Role> roles = roleDAO.getAll();
        
 /*      for (Role role3 : roles) {
		System.out.println(role3.getName());
	}
        
       // HibernateUtil.checkData("select name from role");
        
     //   roleDAO.delete(role);
        
      //  HibernateUtil.checkData("select name from role");
        
        
    
   
	
    /* VER COMO HACER CON USER_ID , porque me pide un idx al usar una lista, al usar un bag no*/
    
	AddressDAO addressDAO = new AddressDAOImpl();
	Address address1 = new Address();
	Address address2 = new Address();
	
	address1.setCity("cordoba");
	address1.setCountry("Argentina");
	address1.setDeparmentNumber("D");
	address1.setFloor("2");
	address1.setStreetName("av. Emilio olmos");
	address1.setStreetNumber("237");
	address1.setZipCode("5000");
	
	address2.setCity("cordoba");
	address2.setCountry("Argentina");
	address2.setDeparmentNumber(null);
	address2.setFloor(null);
	address2.setStreetName("Donaciano del campillo");
	address2.setStreetNumber("1312");
	address2.setZipCode("5009");
	

	
	
	
//	AddressDAO.save(address1);
	
	//HibernateUtil.checkData("SELECT * FROM ADDRESS");
	
	
	// CREATE PHONES
	
	
 	Phone phone1 = new Phone();
	phone1.setType("celular");
	phone1.setNumber("3515178410");
	

	Phone phone2 = new Phone();
	phone2.setType("fijo");
	phone2.setNumber("4816810");
	
	/* CREATE CREDENTIALS */
	

	
	
	
	CredentialDAO credentialDAO = new CredentialDAOImpl();
	Credential credential = new Credential();
	
	credential.setLoginName("fgallardo");
	credential.setPassword("123");
	credential.setExpired(false);
	
	Date today = new Date();
	
	credential.setLastPasswordChange(today); 
    
	
	credentialDAO.save(credential);
	
	
	
//	HibernateUtil.checkData("SELECT * FROM CREDENTIAL");
	
	

	/* CREATE USER */
	
	
	
	UserDAO userDAO = new UserDAOImpl();
	Users user = new Users();
	user.setFirstName("fabian alejandro");

	Users user2 = new Users();
	user2.setFirstName("gustavo sevilla");

		
	ArrayList<Address> addresses = new ArrayList<Address>();

	addresses.add(address1);
    addresses.add(address2);
    user.setAddresses(addresses);
	
    
    ArrayList<Phone> ListPhones = new  ArrayList<Phone>();
    ListPhones.add(phone1);
    ListPhones.add(phone2);
    user.setPhones(ListPhones);

    
    user.setEmail("gallardofabianalejandro@gmail.com");
    
    
    UserStatusLogin userLoggedOff = new UserLoggedOff();
    StatusLoginEnum statusEnum = null;
    
    
    
    
   
    
    System.out.println("guardo el primer usuario");
    
    
    userDAO.save(user);
    
	   
    
    
    Long numero = new Long("1");
    userDAO.get(numero);
    
    user2.setUserStatus(statusEnum.LOGGEDOFF);
    UserStatusLogin userState = new UserLoggedOff();
    System.out.println(  userState.isLoggedOff());
    userState = userState.getUserStatus(user2.getUserStatus());
    System.out.println(  userState.isLoggedOff());
    userState.login(user2);
    userDAO.save(user2);
	

	
	
	userState = userState.getUserStatus(user2.getUserStatus());
	userState.isLogged();
	
	userState.logout(user2);
	
	userDAO.save(user2);
	
	
	
	
    //pruebo grabar status logueado
    
    
    
    userDAO.save(user);
	
	
    StatusLoginEnum status = null;
    
   String Status =     status.LOCKED.toString();
    
	userDAO.save(user2);
	
	Collection<Users> userList = userDAO.getAll();
	
	
 numero = new Long("1");
	
	
		
	System.out.println((userDAO.get(numero)).getFirstName());
	


	
	
	
	
	
	
	}
	
	
	

}
